#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void foo(void) {
	printf("FOO\n");
}

void bar(void) {
	printf("BAR\n");
}

void repeat(void f(void), int n) {
	for (int i = 0; i < n; i++) {
		f();
	}
}

typedef struct {
	int number;
	char name[25];
	int chinese;
	int math;
	int english;
} Student;

int cmp(const void*, const void*);

int main(void) {
	Student stus[5];
	for (int i = 0; i < 5; i++) {
		scanf("%d%s%d%d%d",
			&stus[i].number,
			stus[i].name,
			&stus[i].chinese,
			&stus[i].math,
			&stus[i].english);
	}

	qsort(stus, 5, sizeof(Student), cmp);

	return 0;
}

int cmp(const void* p1, const void* p2) {
	Student* s1 = p1;
	Student* s2 = p2;

	int total1 = s1->chinese + s1->math + s1->english;
	int total2 = s2->chinese + s2->math + s2->english;

	if (total1 != total2) 
		return total2 - total1;

	if (s1->chinese != s2->chinese) 
		return s2->chinese - s1->chinese;

	if (s1->math != s2->math) 
		return s2->math - s1->math;

	if (s1->english != s2->english) 
		return s2->english - s1->english;

	return strcmp(s1->name, s2->name);
}